package com.itheima.d6_charset;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws Exception {
        //1, 编码
        String name ="ABC我爱你123";
        byte[] bytes = name.getBytes();// 不写就是默认字符集 UTF-8
        System.out.println(bytes.length);
        System.out.println(Arrays.toString(bytes));

        byte[] gbks = name.getBytes("GBK");
        System.out.println(gbks.length);

        // 2.解码
        String rs = new String(bytes); //默认UTF-8
        System.out.println(rs);

        String rs1 = new String(gbks,"GBK");
        System.out.println(rs1);
    }
}
